<!-- 开票申请单开票明细 -->
<template>
	<view>
		<u-sticky>
			<u-tabs
				class="tabs" 
				:list="tabsList" 
				@click="onTabClick" 
				:scrollable="false" style="padding: 0 24rpx;background: #FFF;z-index:22;position: sticky;top: 0px;"
				:activeStyle="{color:'#171717', fontSize: '14px'}"
				:inactiveStyle="{color:'#C6C6C6', fontSize: '14px'}"
				lineColor="#1E6FFF"
			></u-tabs>
		</u-sticky>
		<view class="task_lists" :style="{ paddingBottom: tabvalue == '待办'?'130rpx':'0' }">
			<collapse name="基本信息" id="outside1" :maxHeight="maxHeight">
				<view class="listdefault" :id="uId">
					<block v-for="(item,key) in basicInfo" :key="key">
						<view class="action" v-if="item != 'relBillId_dictText'">
							<view class="list1">{{ key }}</view>
							<view class="list2">{{ detailData[item] }}</view>
						</view>
						<block v-if="detailData.isCrossMonthInvalid == '1'">
							<view class="action" v-if="item == 'relBillId_dictText'">
								<view class="list1">{{key}}</view>
								<view class="list2" style="color: #40a9ff;">{{ detailData[item] }}</view>
							</view>
						</block>
					</block>
					
				</view>
			</collapse>
			<action-collapse name="发票信息" :childFields="childFields" id="outside2" :dataSource="childSource">
				<span slot="label" style="color: #dd6161">（作废时开票金额请填负数！)</span>
				<span slot="projectId_dictText" slot-scope="projectId" style="color: #1E6FFF;" @click="onClickProjectName(projectId.record)">{{projectId.text}}</span>
			</action-collapse>
			<action-collapse name="开票信息" :childFields="childFields2" id="outside3" :dataSource="childSource2"></action-collapse>
			<default-list name="附件">
				<file-list :fileList="detailData.attachments"></file-list>
			</default-list>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>
<script>
	import actionCollapse from '@/pages/synergy/components/actionCollapse.vue'
	import detailInformationList from '@/pages/synergy/components/detailInformationList.vue'
	import fileList from '@/pages/synergy/components/fileList.vue'
	import collapse from '@/pages/synergy/components/collapse.vue'
	import defaultList from '@/pages/synergy/components/defaultList.vue'
	import flowList from '@/pages/synergy/components/flowList.vue'
	import {
		queryByIdInvoice, // 根据id查询信息
		getProcessTaskTransInfo, // 查询流程流转信息
		getProcessHistoryList, // 查询流程图信息
		getProcessHistoryTaskList, // 查询历史流程图信息
		getNodePositionInfo, // 查询坐标信息数据
		rejectProcess, // 退回
		processComplete ,// 提交完成
		queryByIdInvoiceChildren,// 子表
		erpFinanceInvoiceHandleRecordList // 开票信息列表
	} from '@/api/index.js'
	import {
		BASE_URL
	} from '@/utils/baseUrl.js'
	export default {
		data() {
			return {
				tabsList: [
					{ name: '基本信息',id: 'outside1' }, 
					{ name: '发票信息',id: 'outside2' },
					{ name: '开票信息',id: 'outside3' }
				],
				detailData: {}, // 详情数据
				maxHeight: 0,
				uId: uni.$u.guid(),
				basicInfo: { // 主表信息字段
					'单据编号': 'billNo',
					'申请人': 'proposer_dictText',
					'申请部门': 'proposerDeptId_dictText',
					'申请时间': 'createTime',
					'销售方单位': 'sellerUnit_dictText',
					'经营团队': 'teamId_dictText',
					// '项目承接人': 'undertaker_dictText',  // 迭代16.7隐藏主表项目承接人
					'开票人': 'invoiceApplicant_dictText',
					'开票类型': 'invoiceCategory_dictText',
					
					// 迭代16.7 主表中字段是否跨月作废改为是否作废
					'是否作废': 'isCrossMonthInvalid_dictText',
					'总开票金额(元)': 'invoiceTotalAmount',
					'关联已开票申请单': 'relBillId_dictText',
					'业主单位': 'buyerUnit_dictText',
					'纳税人识别号': 'taxpayerIdNo',
					'单位地址': 'companyAddress',
					'单位电话': 'companyTel',
					'开户行': 'bankName',
					'银行账号': 'bankAccountNo',
					'发票备注': 'invoiceRemark',
					'附言': 'postscript',
				},
				childFields: { // 发票信息字段
					'项目名称': 'projectId_dictText',
					'项目承接人': 'undertaker_dictText',
					'业绩归属年度': 'attributionYear',
					'经营团队': 'teamId_dictText',
					'项目合同': 'projectContract_dictText',
					'合同款项': 'contractFund_dictText',
					'款项金额(元)': 'itemMoney',
					'预计回款时间': 'estimateRefundTime',
					'开票金额(元)': 'invoiceAmount',
				},
				childFields2: { // 开票信息字段
					'发票号码': 'invoiceNo',
					'开票日期': 'createTime',
					'发票类型': 'invoiceCategory_dictText',
					// '是否收票': 'isFree_dictText',
					'备注': 'remark',
				},
				resultList: [], // 流程图数据
				nodePositionInfo: {}, // 坐标信息
				processInstanceId: '',
				scrollTop: 0, // 滚动顶部距离
				model: {}, // 处理单据表信息
				resultObj: {}, // 流程图流转信息
				nodeObj: {}, // 流程节点信息
				tabvalue: '', // 协同首页tabs name
				childSource: [], // 发票数据
				childSource2: [], // 开票数据
				isClick: false,
				id: ''
			}
		},
		components: {
			actionCollapse,
			detailInformationList,
			fileList,
			collapse,
			defaultList,
			flowList
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onLoad(options) {
			this.id = options.id || ''
			this.loadData(this.id)
		},
		methods: {
			// 查询详情
			async loadData(id){
				queryByIdInvoice({ id }).then(async res => {
					if(res.success){
						this.detailData = res.result
						// 查询子表数据
						this.getChildData(res.result.id)
						this.getChildData2(res.result.id)
						this.timer = setTimeout(() => {
							clearTimeout(this.timer)
							this.timer = null
							this.$nextTick(function() {
								uni.createSelectorQuery().select('#'+this.uId).boundingClientRect(data => {
									this.maxHeight = data.height
								}).exec();
							})
						},300)
					} else {
						this.$refs.uToast.show({
							message: res.message,
							type: 'error'
						})
					}
				})
			},
			// 查询发票信息
			getChildData(id){
				var params = {
					column: 'createTime',
					order: 'desc',
					pageNo: 1,
					pageSize: 100,
					billId: id
				}
				queryByIdInvoiceChildren(params).then(res => {
					if(res.success){
						this.childSource = res.result.records || res.result
					}
				})
			},
			
			// 查询开票信息
			getChildData2(id){
				var params = {
					column: 'createTime',
					order: 'desc',
					pageNo: 1,
					pageSize: 100,
					billId: id,
				}
				erpFinanceInvoiceHandleRecordList(params).then(res => {
					if(res.success){
						this.childSource2 = res.result.records || res.result
					}
				})
			},
			// 点击tabs
			onTabClick (item) {
				uni.createSelectorQuery().in(this).select(`#${item.id}`).boundingClientRect(data => {
					uni.pageScrollTo({
						scrollTop:data.top + this.scrollTop - 54,
						duration: 150
					})
				 }).exec();
			},
			// 点击项目名称
			onClickProjectName (item) {
				uni.redirectTo({
					url: '/pages/reportFilesList/erpProjectReportListDetail?id=' + item.projectId
				})
			},
		}
	}
</script>
<style lang="scss" scoped>
@import "@/pages/synergy/common/action.scss";
.task_lists{
	padding: 20rpx 20rpx 0;
}
.image_lists{
	padding: 0 0 12rpx 12rpx;
	display: flex;
	flex-wrap: wrap;
	.image_list{
		margin-bottom: 20rpx;
		width: 144rpx;
		margin-right: 14rpx;
		.image_img{
			width: 116rpx;
			height: 116rpx;
			padding: 12rpx;
			background: rgba(0,0,0,0.0200);
			border-radius: 1px;
			border: 1px solid rgba(0,0,0,0.0800);
			position: relative;
			.image_action{
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translateX(-50%) translateY(-50%);
				width: 36rpx;
				height: 36rpx;
			}
			.image_source{
				width: 100%;
				height: 100%;
			}
		}
		.image_name{
			font-size: 20rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #B2B2B2;
			line-height: 28rpx;
			margin-top: 8rpx;
			text-align: left;
			overflow:hidden;
			white-space:nowrap;
			text-overflow:ellipsis;
			width: 152rpx;
		}
	}
}

.flow_right{
	display: flex;
	align-items: center;
	image{
		width: 40rpx;
		height: 40rpx;
	}
	text{
		font-size: 14px;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #1E6FFF;
		line-height: 40rpx;
		margin-left: 4rpx;
	}
}

.task_bottom{
	display: flex;
	align-items: center;
	padding: 20rpx 0 20rpx 52rpx;
	background-color: #FFFFFF;
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	z-index: 10000;
	.task_bottom_write{
		display: flex;
		align-items: center;
		image{
			width: 48rpx;
			height: 48rpx;
			margin-right: 8rpx;
		}
		text{
			font-size: 28rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #7F7F7F;
			line-height: 40rpx;
		}
	}
	.refuse{
		width: 168rpx;
		height: 90rpx;
		line-height: 90rpx;
		background: rgba(0,0,0,0.0500);
		border-radius: 10rpx;
		margin: 0 16rpx 0 52rpx;
		font-size: 34rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: rgba(0,0,0,0.5000);
		text-align: center;
	}
	.agree{
		width: 318rpx;
		height: 90rpx;
		line-height: 90rpx;
		background: #1E6FFF;
		border-radius: 10rpx;
		font-size: 34rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		text-align: center;
	}
}
</style>
